<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="dao.Entity.PlaceSchedule"%>
<%@page import="dao.Entity.PlaceTime"%>
<%@page import="dao.QueryPlaceSchedule"%>
<%@page import="java.util.ArrayList"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="shortcut icon"  href="image/icon6.ico" type="image/x-icon" /> 
        <link href="css/allcss.css" rel="stylesheet" type="text/css"/>
        <script src="./script/jquery.js" type="text/javascript"></script>
        <style>
            #op4{
                color:#00aeec;
            }
        </style>
        <title>Places</title>
    </head>
    <body>
        <div id="aside">
            <img id="icon" src="./image/icon6.png">
            <div id="p1">管理员界面</div>    
        </div>
        <div id="main">
            <div id="list"><div id="op1" class="options">全部预约</div><div  id="op2" class="options">未审核</div>
                <div  id="op3" class="options">已审核</div><div  id="op4" class="options">地点管理</div>
                <div  id="op5" class="options">地点上新</div><div  id="op6" class="options">数据库管理</div>
                <div  id="op7" class="options">学生信用度</div><div  id="op8" class="options">申诉回复</div>
            </div>
            <div id="content">
                <%
                    PlaceSchedule res = null;
                    String placenumber = request.getParameter("placenumber");
                    String button1 = "<button id='button2'  onclick='add(event)' value='" + placenumber + "' >新增时间段</button>";
                    if (placenumber != null) {
                        res = QueryPlaceSchedule.getResult(placenumber);
                        out.print("<div id='placeposition'>" + res.name + "</div>" + button1);
                        for (int i = 0; i < res.Schedule.size(); i++) {
                            PlaceTime placetime = res.Schedule.get(i);
                            out.print("<div  class='reservations'><div class='reservation'>日期：[" + placetime.PlaceDate + "]</div>");
                            for (int j = 0; j < placetime.TimeTable.size(); j++) {
                                String color = "red";
                                if (placetime.TimeTable.get(j).Status) {
                                    color = "green";
                                }
                                String button2 = "<button id='button3 " + placetime.TimeTable.get(j).PlaceTimeNumber + "'  class='button3' onclick='add1(event)' value='" + placetime.TimeTable.get(j).PlaceTimeNumber + "' >更新</button>";
                                out.print("<div class='detailtime'>时间号：[" + placetime.TimeTable.get(j).PlaceTimeNumber + "] 开始时间：[" + placetime.TimeTable.get(j).StartTime + "] 结束时间：["
                                        + placetime.TimeTable.get(j).EndTime + "]</div><img class='status_img' src='./image/" + color + ".png'/>"
                                        + button2);
                            }
                            out.print("</div>");
                        }
                    }
                %>
            </div>
        </div>
        <script src="./script/button.js" type="text/javascript"></script>
        <script>
            const urlParams = new URLSearchParams(window.location.search);
            var placeNumber = urlParams.get('placenumber');
            var placename = $("#placeposition").text();
            function add(event) {
                var id = event.target.id;
                var no = event.target.value;
                window.location.href = "addNewPlaceTime.html?PlaceNumber=" + no + "&placename=" + placename;
            }
            function add1(event) {
                var id = event.target.id;
                var no = event.target.value;
                window.location.href = "updatePlaceTimeStatus.jsp?placetimenumber=" + no + "&placenumber=" + placeNumber;
            }
        </script>    
    </body>
</html>
